package mest.service.cxj.impl;

import mest.VO.cxj.ProductJobVO;
import mest.dao.cxj.ProductJobDao;
import mest.entity.product_job;
import mest.service.cxj.ProductJobService;
import mest.util.ObjectUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class ProductJobServiceImpl implements ProductJobService {

    @Resource
    private ProductJobDao productJobDao;

    @Override
    public int insertProductJob(List<ProductJobVO> spJVO,String theirDb) {
        return productJobDao.insertProductJob(spJVO,theirDb);
    }

    @Override
    public int updateProductJob(List<ProductJobVO> spJVO,String theirDb) {
        return productJobDao.updateProductJob(spJVO,theirDb);
    }


    public List<ProductJobVO> setSpJobVO(Integer poId, List<ProductJobVO> spJobVO) {
        spJobVO.removeAll(Collections.singleton(null));  //剔除空元素
        for (int i = 0; i < spJobVO.size(); i++) {   //生产作业设置生产单Id
            if (spJobVO.get(i) != null)
                spJobVO.get(i).setPoId(poId);
        }
        return spJobVO;
    }

    @Override
    public boolean isExitId(List<ProductJobVO> spJobVO) {
        boolean isExit = true;  //标识作业单ID是否存在，否则不能修改,默认存在为true
        for (ProductJobVO productJobVO:spJobVO){
            if (!ObjectUtil.contains(productJobVO, "id")){
                isExit=false;   //若检测出ID不存在，则为false
            }
        }
        return isExit;
    }

    @Override
    public List<ProductJobVO> selectAllproductJobByPoId(Integer page, Integer limit, Integer poId,String theirDb) {
        return productJobDao.selectAllproductJobByPoId((page - 1) * limit, limit, poId,theirDb);
    }

    @Override
    public int selectCountproductJobByPoId(Integer poId,String theirDb) {
        return productJobDao.selectCountproductJobByPoId(poId,theirDb);
    }

    @Override
    public List<product_job> selectby_poId(Integer poId) {
        return productJobDao.selectby_poId(poId);
    }


}
